package bcMedTests;

import java.sql.Date;
import java.util.List;

import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import bcMedBeans.*;
import bcMedEntity.EntityDataBase;
import bcMedEntity.EntityDataBaseRead;
import bcMedEntity.EntityDataBaseSearch;

public class TestEntityDataBaseSearch {


	EntityDataBase testeDb;
	
	@BeforeClass
	public void setUp() {
		testeDb = new EntityDataBase();
	}
	
	@Test
	public void testDrivePresente() {
		assert testeDb.isDriverPresent();
	}
	
	
	@Test
	public void testGetConsultaAll() {
		testeDb.connectDataBase();
		EntityDataBaseSearch dbSearch = new EntityDataBaseSearch(testeDb);
		List<Consulta> consultaList= dbSearch.getConsultaAll();
		boolean c1 = consultaList.get(0).getIdConsulta() == 1;
		boolean c2 = consultaList.get(0).getPaciente().getIdPaciente() == 1;
		boolean c3 = consultaList.get(0).getMedico().getIdMedico() == 1;
		boolean c4 = consultaList.get(0).getStatusConsulta().getIdStatusConsulta() == 4;
		boolean c5 = consultaList.get(0).getTipoConsulta().getIdTipoConsulta() == 1;
		assert (c1 && c2 && c3 && c4 && c5);
	}
	
	
	@Test
	public void testGetEnderecoAll() {
		testeDb.connectDataBase();
		EntityDataBaseSearch dbSearch = new EntityDataBaseSearch(testeDb);
		List<Endereco> enderecoList= dbSearch.getEnderecoAll();
		boolean c1 = enderecoList.get(0).getBairro().equals("jardim do sul");
		boolean c2 = enderecoList.get(0).getCep().equals("12200-200");
		boolean c3 = enderecoList.get(0).getCidade().equals("Sao Jose dos Campos");
		boolean c4 = enderecoList.get(0).getNumero() == 110;
		boolean c5 = enderecoList.get(0).getEstado().equals("sao paulo");
		assert (c1 && c2 && c3 && c4 && c5);
	}
	
	@Test
	public void testGetMedicoAll() {
		testeDb.connectDataBase();
		EntityDataBaseSearch dbSearch = new EntityDataBaseSearch(testeDb);
		List<Medico> medicoList= dbSearch.getMedicoAll();	
		boolean c1 = medicoList.get(0).getNome().equals("Medico A");
		boolean c2 = medicoList.get(1).getNome().equals("Medico B");
		
		assert c1 && c2 ;
		
	}
	
	@Test
	public void testGetPacienteAll() {
		testeDb.connectDataBase();
		EntityDataBaseSearch dbSearch = new EntityDataBaseSearch(testeDb);
		List<Paciente> pacienteList= dbSearch.getPacienteAll();	
		boolean c1 = pacienteList.get(0).getNome().equals("Nome A da Silva");
		boolean c2 = pacienteList.get(0).getCadastro().equals(new Date(110, 4, 10));
		boolean c3 = pacienteList.get(0).getEndereco().getIdEndereco()==1;
		boolean c4 = pacienteList.get(0).getIdade()==33;
		boolean c5 = pacienteList.get(0).getPlanoSaude().getIdPlanoSaude()==1;
		boolean c6 = pacienteList.get(0).getSexo() == 'm';
		assert c1&&c2&&c3&&c4&&c5&&c6 ;
		
	}
	
	
	@Test
	public void testGetStatusConsultaAll() {
		testeDb.connectDataBase();
		EntityDataBaseSearch dbSearch = new EntityDataBaseSearch(testeDb);
		List<StatusConsulta> statusConsultaList= dbSearch.getStatusConsultaAll();
		boolean c1 = statusConsultaList.get(0).getNome().equals("agendado");
		boolean c2 = statusConsultaList.get(5).getNome().equals("confirmar");
		assert (c1 && c2);
	}
	
	
	
	@Test
	public void testGetTipoConsultaAll() {
		testeDb.connectDataBase();
		EntityDataBaseSearch dbSearch = new EntityDataBaseSearch(testeDb);
		List<TipoConsulta> tipoConsultaList= dbSearch.getTipoConsultaAll();
		boolean c1 = tipoConsultaList.get(0).getNome().equals("Procedimento A");
		boolean c2 = tipoConsultaList.get(5).getNome().equals("Procedimento F");
		assert (c1 && c2);
	}
	
	@Test
	public void testGetConsultaRestricted() {
		testeDb.connectDataBase();
		EntityDataBaseSearch dbSearch = new EntityDataBaseSearch(testeDb);
		List<Consulta> consultaList= dbSearch.getConsultaRestricted("idconsulta = 4");
		boolean c1 = consultaList.get(0).getIdConsulta() == 4;
		boolean c6 = consultaList.get(0).getData().equals(new Date(110, 4, 20));
		boolean c2 = consultaList.get(0).getPaciente().getIdPaciente() == 5;
		boolean c3 = consultaList.get(0).getMedico().getIdMedico() == 1;
		boolean c4 = consultaList.get(0).getStatusConsulta().getIdStatusConsulta() == 6;
		boolean c5 = consultaList.get(0).getTipoConsulta().getIdTipoConsulta() == 2;
		assert (c1 && c2 && c3 && c4 && c5 && c6);
	}
	
	
	@Test
	public void testGetEnderecoRectricted() {
		testeDb.connectDataBase();
		EntityDataBaseSearch dbSearch = new EntityDataBaseSearch(testeDb);
		List<Endereco> enderecoList= dbSearch.getEnderecoRestricted("idendereco = 5");
		boolean c1 = enderecoList.get(0).getBairro().equals("jardim industrial");
		boolean c2 = enderecoList.get(0).getCep().equals("11100-200");
		boolean c3 = enderecoList.get(0).getCidade().equals("Jacarei");
		boolean c4 = enderecoList.get(0).getNumero() == 15;
		boolean c5 = enderecoList.get(0).getEstado().equals("sao paulo");
		assert (c1 && c2 && c3 && c4 && c5);
	}
	
	
	
	
	@Test
	public void testGetMedicoRestricted() {
		testeDb.connectDataBase();
		EntityDataBaseSearch dbSearch = new EntityDataBaseSearch(testeDb);
		List<Medico> medicoList= dbSearch.getMedicoRestricted("idmedico = 4");
		boolean c1 = medicoList.size() == 1;
		boolean c2 = medicoList.get(0).getIdMedico() == 4;
		boolean c3 = medicoList.get(0).getNome().equals("Medico D");
		assert (c1 && c2 && c3);
	}
	
	
	@Test
	public void testGetPacienteRestricted() {
		testeDb.connectDataBase();
		EntityDataBaseSearch dbSearch = new EntityDataBaseSearch(testeDb);
		List<Paciente> pacienteList= dbSearch.getPacienteRestricted("idpaciente = 2");	
		boolean c1 = pacienteList.get(0).getNome().equals("Nome B da Silva");
		boolean c2 = pacienteList.get(0).getCadastro().equals(new Date(110, 4, 10));
		boolean c3 = pacienteList.get(0).getEndereco().getIdEndereco()==2;
		boolean c4 = pacienteList.get(0).getIdade()==40;
		boolean c5 = pacienteList.get(0).getPlanoSaude().getIdPlanoSaude()==1;
		boolean c6 = pacienteList.get(0).getSexo() == 'm';
		assert c1&&c2&&c3&&c4&&c5&&c6 ;
		
	}
	
	
	
	@Test
	public void testGetStatusConsultaRestricted() {
		testeDb.connectDataBase();
		EntityDataBaseSearch dbSearch = new EntityDataBaseSearch(testeDb);
		List<StatusConsulta> statusConsultaList= dbSearch.getStatusConsultaRestricted("idstatus_consulta = 2");
		boolean c1 = statusConsultaList.size() == 1;
		boolean c2 = statusConsultaList.get(0).getNome().equals("remarcado");
		assert (c1 && c2);
	}
	
	
	
	@Test
	public void testGetTipoConsultaRestricted() {
		testeDb.connectDataBase();
		EntityDataBaseSearch dbSearch = new EntityDataBaseSearch(testeDb);
		List<TipoConsulta> tipoConsultaList= dbSearch.getTipoConsultaRestricted("idtipo_consulta = 2");
		boolean c1 = tipoConsultaList.size() == 1;
		boolean c2 = tipoConsultaList.get(0).getNome().equals("Procedimento B");
		assert (c1 && c2);
	}
	

}
